package com.uton.rfidcontroller.viewmodel.activity_model;

import android.databinding.ObservableField;

import com.uton.rfidcontroller.common.interfaces.INetController;
import com.uton.rfidcontroller.common.net.RetrofitFactory;
import com.uton.rfidcontroller.model.CarDetailModel;
import com.uton.rfidcontroller.viewmodel.base.BaseViewModel;

import java.util.HashMap;

/**
 * Created by 王家宝 on 2017/10/11.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public abstract class CarDetailActivityViewModel extends BaseViewModel {

    private String carId;

    public final ObservableField<String> carName = new ObservableField<>("");
    public final ObservableField<String> plateNumber = new ObservableField<>("");
    public final ObservableField<String> cBrand = new ObservableField<>("");
    public final ObservableField<String> cType = new ObservableField<>("");
    public final ObservableField<String> cModel = new ObservableField<>("");
    public final ObservableField<String> miles = new ObservableField<>("");
    public final ObservableField<String> firstUpTime = new ObservableField<>("");
    public final ObservableField<String> ariableBox = new ObservableField<>("");
    public final ObservableField<String> carColour = new ObservableField<>("");
    public final ObservableField<String> displacement = new ObservableField<>("");
    public final ObservableField<String> engine = new ObservableField<>("");

    public CarDetailActivityViewModel(String carId) {
        this.carId = carId;
        refreshData();
    }

    @Override
    public void refreshData() {
        HashMap<String, Object> tempData = new HashMap<>();
        tempData.put("carId", carId);
        go(RetrofitFactory.getInstance().carDetail(tempData), new INetController<CarDetailModel>() {
            @Override
            public void onSuccess(CarDetailModel response) {
                carName.set(response.getCarName());
                plateNumber.set(response.getPlateNumber());
                cBrand.set(response.getCBrand());
                cType.set(response.getCType());
                cModel.set(response.getCModel());
                miles.set(response.getMiles());
                firstUpTime.set(response.getFirstUpTime());
                ariableBox.set(response.getAriableBox());
                carColour.set(response.getCarColour());
                displacement.set(response.getDisplacement());
                engine.set(response.getEngine());
            }

            @Override
            public void onError() {

            }

            @Override
            public void onComplete() {

            }
        });
    }

}
